package com.bll.imple.mymienAction;

import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.bean.MymienBean;
import com.bean.PictureBean;
import com.bll.UploadAction;
import com.dao.MymienDao;
import com.dao.PictureDao;
import com.jspsmart.upload.SmartUpload;
public class UpdateMymienAction implements UploadAction{
	public String execute(ServletConfig servletCongfig, HttpServletRequest request,
			HttpServletResponse response) {
		 
		SmartUpload su = new SmartUpload();
		String lujing="";
		try {
			su.initialize(servletCongfig,request,response);
			su.setMaxFileSize(5*1024*1024);
			su.setTotalMaxFileSize(1024*1024);
			su.setAllowedFilesList("jpg,jpeg,gif,bmp,png");
			su.setDeniedFilesList("exe,bat");
			su.upload();
			
			String titleInfo=su.getRequest().getParameter("titleInfo");
			String textInfo=su.getRequest().getParameter("textInfo");
			lujing=request.getParameter("lujing");
			String addtime=request.getParameter("addTime");
//			System.out.println("ulujing:"+lujing);
			System.out.println("titleInfo:"+titleInfo+" "+"textInfo:"+textInfo);
//			System.out.println("tid:"+Integer.parseInt(request.getParameter("typeId")));
			 int id=Integer.parseInt(su.getRequest().getParameter("id"));
			 MymienBean bean=new MymienBean();
			    bean.setTextInfo(textInfo);
			    bean.setTitleInfo(titleInfo);
			    bean.setId(id);
			    bean.setAddTime(addtime);
			    String pictureExt= su.getFiles().getFile(0).getFileExt();
				String pictureName = su.getFiles().getFile(0).getFileName();
				String picturePath="/PicUpload/"+pictureName;
				su.save("/PicUpload");
				bean.setPicturePath(picturePath);
            	MymienDao dao=new MymienDao();
            	dao.UpdateMymien(bean);
            	if(bean.getType()==1){
            		PictureDao pdao=new PictureDao();
                	PictureBean pbean=new PictureBean();
                	pbean.setPictureName(pictureName);
                	pbean.setPicturePath(picturePath);
                	pbean.setPictureExt(pictureExt);
                	pbean.setPosition("mymien");
                	pbean.setUserId(bean.getUserId());
                	pdao.addPicture(pbean);
            	}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return lujing+"?lujing="+request.getParameter("lujing1")+"&typeId="+Integer.parseInt(request.getParameter("typeId"));
	    //return "ShowMymien";
	}
}
